package com.woniuxy.service.basics.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.BookMapper;
import com.woniuxy.pojo.Book;
import com.woniuxy.service.basics.BookService;

@Service
public class BookServiceImpl implements BookService {

	@Autowired
	private BookMapper bookMapper;

	@Override
	public List<String> selectByParentName(String name) {
		return bookMapper.selectByParentName(name);
	}

	@Override
	public PageInfo selectAll(Integer pn, String condition) {
		PageHelper.startPage(pn, 3);
		List<Book> list = bookMapper.selectAllByParentName(condition);
		PageInfo pageInfo = new PageInfo(list,3);
		return pageInfo;
	}

	@Override
	public List<String> selectMenu() {
		return bookMapper.selectMenu();
	}

	@Override
	public List<String> selectMenu2(String condition) {
		// TODO Auto-generated method stub
		return bookMapper.selectMenu2(condition);
	}

	@Override
	public List<Book> selectMenuByLevel(String bookLevel) {
		// TODO Auto-generated method stub
		return bookMapper.selectMenuByLevel(Integer.parseInt(bookLevel)-1);
	}

	@Override
	public void addBook(Book book) {
		bookMapper.insert(book);		
	}

	@Override
	public Book selectByBookId(Integer bookId) {
		return bookMapper.selectByPrimaryKey(bookId);	
	}

	@Override
	public String selectNameById(Integer bookid) {
		// TODO Auto-generated method stub
		return bookMapper.selectNameById(bookid);
	}

	@Override
	public void updateBook(Book book) {
		// TODO Auto-generated method stub
		bookMapper.updateByPrimaryKey(book);
	}

}
